define(['jquery', 'widget/calendar', 'widget/tree', 'widget/table'], function ($, calendar, tree, table) {


    var cal = calendar({
        selector: '#test'
    });


    cal.bindEvent({
        'btn.ok.click': function (e, c) {
            console.log(c);
            var v = c.getValue();
            $('#test').val(v.startdate + '~' + v.enddate);
        },
        'btn.cancel.click': function (e, c) {
            console.log(c.getValue())
        }
    });

    var cal1 = calendar({
        selector: '#test1',
        enableFutureDate:true,
        this11:'1'
    });

    console.log(cal);
    console.log(cal1);

    cal1.bindEvent({
        'btn.ok.click': function (e, c) {
            console.log(c);
            var v = c.getValue();
            $('#test1').val(v.startdate + '~' + v.enddate);
        },
        'btn.cancel.click': function (e, c) {
            console.log(c.getValue())
        }
    });

    var treeData = {
        id: '1',
        text: '肯德基',
        children: [{
            id: '2',
            text: '湖北省',
            children: [{
                id: '3',
                text: '武汉市',
                children: [{
                    id: '4',
                    text: '洪山区',
                    children: [{
                        id: '5',
                        text: '波波城店',
                        cls: 'store',
                        children: []
                    }, {
                        id: '6',
                        text: '剑桥餐厅',
                        cls: 'store',
                        children: []
                    }]
                }]
            }, {
                id: '7',
                text: '宜昌市',
                children: [{
                    id: '8',
                    text: '西陵区',
                    children: [{
                        id: '9',
                        cls: 'store',
                        text: '东山店',
                        children: []
                    }, {
                        id: '10',
                        cls: 'store',
                        text: '泰富广场店',
                        children: []
                    }]
                }]
            }]
        }, {
            id: '11',
            text: '广东省',
            children: []
        }, {
            id: '12',
            text: '湖南省',
            children: []
        }]
    };

    /*
     tree({
     treeData: treeData
     }).show();
     */

    var tt = table({
        url: 'static/data/table.json',
        renderTo: '#tt',
        fields: [
            {title: '姓名', name: 'a', sort: true, type: 'string'},
            {title: '性别', name: 'b'},
            {title: '电话', name: 'c'},
            {title: '创建时间', name: 'd', sort: true, type: 'date'},
            {title: '地址', name: 'e'}
        ]
    });

    console.log(tt);

    var tpl = '{{c}}<table>' +
        '<tr>  ' +
        '<td>  {{a}}</td>' +
        '<td>{{b}}</td>' +
        '</tr>' +
        '</table>{{e}}<span></span>';


    function tpl2Html(data) {

        var str = tpl.split(/\{\{.+?\}\}/g);
        var tag = tpl.match(/(\{\{(.+?)\}\})/g);

        var prop = /\{\{\s*[\w\W]+\s*\}\}/;
        var output = '';
        for (var i = 0; i < tag.length; i++) {
            output += str[i];
            if (prop.test(tag[i])) {
                var prop1 = tag[i].substr(2, tag[i].length - 4);
                output += data[prop1];
            }
        }

        output += str[i];

        console.log(str, tag);
        console.log(output);
    }

    tpl2Html({
        c: 1,
        a: 2,
        b: 3,
        e: 4
    })


});